<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=BoDHWfB34TUhSDodZSudcbo0"></script>
    <script type="text/javascript" src="http://api.map.baidu.com/library/Heatmap/2.0/src/Heatmap_min.js"></script>
	<link href="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://api.map.baidu.com/library/TrafficControl/1.4/src/TrafficControl_min.js"></script>
    <script type="text/javascript" src="<c:url value='/resource/js/common.js'/>"></script>
    <title>热力图</title>
    <style type="text/css">
		ul,li{list-style: none;margin:0;padding:0;float:left;}
		html{height:100%}
		body, html,#container {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
    </style>	
</head>
<body>
	<div id="container"></div>
	
</body>
</html>
<script type="text/javascript">
    var map = new BMap.Map("container");          // 创建地图实例

    var mapLng = -1;
    var mapLat = -1;
    map.centerAndZoom(new BMap.Point(125.32996314925, 43.891229197967), 15);
    map.enableScrollWheelZoom(); // 允许滚轮缩放

    var point = new BMap.Point(125.32996314925, 43.891229197967);


    //用户当前位置标注点；
    var userLocaMarker = new BMap.Marker(point, {icon: new BMap.Symbol(BMap_Symbol_SHAPE_POINT,{
        scale: 1,//图标缩放大小
        fillColor: "#3B71CC",//填充颜色
        fillOpacity: 1,//填充透明度
        strokeColor: "white",
        strokeOpacity: .9
    })});
    var showlocalInfo = false;
    var infoArray = new Array();
    var address = "";
    var userGeoc = new BMap.Geocoder();
    userLocaMarker.addEventListener("click", function localInfo(){
        var infoOverlay = new RouteInfoOverlay(userLocaMarker.getPosition(),address);
        map.addOverlay(infoOverlay);
        infoArray.push(infoOverlay);
        if(!showlocalInfo){
            showlocalInfo = true;
        }else {
            $.each(infoArray, function(i,n){
                map.removeOverlay(n);
            });
            showlocalInfo = false;
        }
    });

    //地图定位服务
    var geolocationControl = new BMap.GeolocationControl({
        anchor : BMAP_ANCHOR_TOP_RIGHT,
    });

    geolocationControl.addEventListener("locationError", function(e) {
        //alert("定位失败");
    });
    map.addControl(geolocationControl);

    var geolocation = new BMap.Geolocation();
    //alert("正在定位...")
    geolocation.getCurrentPosition(function(r){
        if(this.getStatus() == BMAP_STATUS_SUCCESS){
            userLocaMarker.setPosition(r.point);
            userGeoc.getLocation(r.point, function(res){
                address = res.addressComponents.city+res.addressComponents.district+"<br>"+res.addressComponents.street+res.addressComponents.streetNumber;
            });
            map.addOverlay(userLocaMarker);
            if(mapLng!="-1" && mapLat!="-1"){
                map.panTo(new BMap.Point(mapLng,mapLat))
                var objs = document.getElementsByName("search_condition");
                var mobj;
                $.each(objs, function(i,n){
                    if(n.innerText == searchName){
                        mobj = n;
                    }
                });
                search_2(searchName, searchID, mobj);
            }else{
                map.panTo(r.point);
            }
            g_lat = r.point.lat;
            g_lng = r.point.lng;
            //alert("定位成功");
        }else {
            //alert("定位失败");
        }
    }, {
        enableHighAccuracy : true
    });
  
    var points = [
	{ "lng": 125.32997, "lat": 43.891234, "count": 100 },
	{ "lng": 125.32986, "lat": 43.891255, "count": 100 },
	{ "lng": 125.32996, "lat": 43.891267, "count": 100 },
	{ "lng": 125.329535, "lat": 43.891987, "count": 100 },
	{ "lng": 125.329974, "lat": 43.891233, "count": 100 },
	{ "lng": 125.32899, "lat": 43.895678, "count": 100 },
	{ "lng": 125.32987, "lat": 43.894567, "count": 100 },
	{ "lng": 125.32889, "lat": 43.8912234, "count": 100 },
	{ "lng": 125.328765, "lat": 43.894562, "count": 100 },
	{ "lng": 125.329567, "lat": 43.898766, "count": 100 },
    { "lng": 125.33017, "lat": 43.82178, "count": 100 },
    { "lng": 125.357038, "lat": 43.869817, "count": 51 },
    { "lng": 125.332766, "lat": 43.948605, "count": 15 },
    { "lng": 125.29485, "lat": 43.839616, "count": 40 },
    { "lng": 125.380736, "lat": 43.871052, "count": 64 },
    { "lng": 126.556073, "lat": 43.843512, "count": 41 },
    { "lng": 126.580813, "lat": 43.88795, "count": 54 },
    { "lng": 123, "lat": 12312, "count": 100 }];
   
    if(!isSupportCanvas()){
    	alert('热力图目前只支持有canvas支持的浏览器,您所使用的浏览器不能使用热力图功能~')
    }
	//详细的参数,可以查看heatmap.js的文档 https://github.com/pa7/heatmap.js/blob/master/README.md
	//参数说明如下:
	/* visible 热力图是否显示,默认为true
     * opacity 热力的透明度,1-100
     * radius 势力图的每个点的半径大小   
     * gradient  {JSON} 热力图的渐变区间 . gradient如下所示
     *	{
			.2:'rgb(0, 255, 255)',
			.5:'rgb(0, 110, 255)',
			.8:'rgb(100, 0, 255)'
		}
		其中 key 表示插值的位置, 0~1. 
		    value 为颜色值. 
     */
	heatmapOverlay = new BMapLib.HeatmapOverlay({"radius":20});
	map.addOverlay(heatmapOverlay);
	heatmapOverlay.setDataSet({data:points,max:100});
	//是否显示热力图
    function openHeatmap(){
        heatmapOverlay.show();
    }
	function closeHeatmap(){
        heatmapOverlay.hide();
    }
	//closeHeatmap();
    function setGradient(){
     	/*格式如下所示:
		{
	  		0:'rgb(102, 255, 0)',
	 	 	.5:'rgb(255, 170, 0)',
		  	1:'rgb(255, 0, 0)'
		}*/
     	var gradient = {};
     	var colors = document.querySelectorAll("input[type='color']");
     	colors = [].slice.call(colors,0);
     	colors.forEach(function(ele){
			gradient[ele.getAttribute("data-key")] = ele.value; 
     	});
        heatmapOverlay.setOptions({"gradient":gradient});
    }
	//判断浏览区是否支持canvas
    function isSupportCanvas(){
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    }
</script>